home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 2: CDPD 1
/
Almathera Ten on Ten - Disc 2: CDPD 1.iso
/
pd
/
301-325
/
306
/
rexxplplot
/
rexxsrc
/
rexxplplot.c
< prev
Wrap
C/C++ Source or Header
|
1995-03-14
|
27KB
|
1,117 lines
/* RexxPlPlot V0.2 - an ARexx front-end to PlPlot
* - written by Glenn M. Lewis - Caltech - 9/12/89
* - based on code by Tomas Rokicki of Radical Eye Software
*/
#include <stdio.h>
#include <ctype.h>
#include "minrexx.h"
#define MAX(m,n) ((m)>(n)?(m):(n))
/* These are the functions we want to patch into */
void pladv(), plbeg(), plbin(), plbox(), plbox3(), plclr(),
plcol(), plcont(), plend(), plenv(), plerrx(), plerry(),
plfont(), plgra(), plgrid3(), plgspa(),
plhist(), pljoin(), pllab(), plline(), plmtex(),
plot3d(), plpoin(), plptex(),
plschr(), plside3(), plsmaj(), plsmin(), plssym(), plstar(),
plstyl(), plsvpa(), plsym(), pltext(), plthicken(),
plvpor(), plvsta(), plw3d(), plwind(), xform(), set_transformation();
void *malloc(), disp();
double atof();
int get_next_int();
float get_next_float();
char *get_char_pointer(), *parse_arg();
void get_float_array(), get_2D_float_array(), get_int_array(),
write_next_float();
/* Static Variables */
static int still_going; /* Flag to shut down RexxPlPlot */
static int parsed, quoted; /* Flag to represent parsing success */
static int return_result; /* Flag whether function returns result */
static char return_string[256]; /* Actual return result string */
float tr[6] = { 1.0, 0.0, 0.0, 0.0, 1.0, 0.0 };
/* Here are all of the patching rountines */
void Rpladv(msg, s)
struct RexxMsg *msg;
char *s;
{
int sub;
sub = get_next_int(msg, &s);
#ifdef DEBUG
printf("pladv(%d);\n", sub);
#endif
if (parsed) pladv(sub);
}
void Rplbeg(msg, s)
struct RexxMsg *msg;
char *s;
{
int dev, nx, ny;
dev = get_next_int(msg, &s);
nx = get_next_int(msg, &s);
ny = get_next_int(msg, &s);
#ifdef DEBUG
printf("plbeg(%d,%d,%d);\n", dev,nx,ny);
#endif
if (parsed) plbeg(dev, nx, ny);
}
void out_of_mem() ; /* forward declare this routine */
void Rplbin(msg, s)
struct RexxMsg *msg;
char *s;
{
int nbin, cen;
float *x=0, *y=0;
nbin = get_next_int(msg, &s);
if (!parsed) return;
if (nbin) {
if (!(x = (float *) malloc(2*nbin*sizeof(float)))) out_of_mem();
y = &x[nbin];
get_float_array(msg, &s, x, nbin);
get_float_array(msg, &s, y, nbin);
cen = get_next_int(msg, &s);
#ifdef DEBUG
printf("plbin(%d,%08x,%08x,%d);\n", nbin, x, y, cen);
#endif
}
if (parsed) plbin(nbin, x, y, cen);
if (nbin) free((void *) x);
}
void Rplbox(msg, s)
struct RexxMsg *msg;
char *s;
{
char *xopt, *yopt;
float xtick, ytick;
int nxsub, nysub;
xopt = get_char_pointer(msg, &s);
xtick = get_next_float(msg, &s);
nxsub = get_next_int(msg, &s);
yopt = get_char_pointer(msg, &s);
ytick = get_next_float(msg, &s);
nysub = get_next_int(msg, &s);
#ifdef DEBUG
printf("plbox('%s',%0.4f,%d,'%s',%0.4f,%d);\n",
xopt, xtick, nxsub, yopt, ytick, nysub);
#endif
if (parsed) plbox(xopt, xtick, nxsub, yopt, ytick, nysub);
}
void Rplbox3(msg, s)
struct RexxMsg *msg;
char *s;
{
char *xopt, *xlabel, *yopt, *ylabel, *zopt, *zlabel;
float xtick, ytick, ztick;
int nxsub, nysub, nzsub;
xopt = get_char_pointer(msg, &s);
xlabel = get_char_pointer(msg, &s);
xtick = get_next_float(msg, &s);
nxsub = get_next_int(msg, &s);
yopt = get_char_pointer(msg, &s);
ylabel = get_char_pointer(msg, &s);
ytick = get_next_float(msg, &s);
nysub = get_next_int(msg, &s);
zopt = get_char_pointer(msg, &s);
zlabel = get_char_pointer(msg, &s);
ztick = get_next_float(msg, &s);
nzsub = get_next_int(msg, &s);
#ifdef DEBUG
printf("plbox3('%s','%s',%0.4f,%d,'%s','%s',%0.4f,%d,'%s','%s',%0.4f,%d);\n",
xopt,xlabel,xtick,nxsub,yopt,ylabel,ytick,nysub,zopt,zlabel,ztick,nzsub);
#endif
if (parsed) plbox3(xopt,xlabel,xtick,nxsub,yopt,ylabel,ytick,nysub,zopt,zlabel,ztick,nzsub);
}
void Rplclr(msg, s)
struct RexxMsg *msg;
char *s;
{
#ifdef DEBUG
printf("plclr();\n");
#endif
plclr();
}
void Rplcol(msg, s)
struct RexxMsg *msg;
char *s;
{
int color;
color = get_next_int(msg, &s);
#ifdef DEBUG
printf("plcol(%d);\n", color);
#endif
if (parsed) plcol(color);
}
void Rplcont(msg, s)
struct RexxMsg *msg;
char *s;
{
float *z, *clevel;
int nx, ny, kx, lx, ky, ly, nlevel;
char *tmp_s = &return_string[0];
strcpy(tmp_s, s); /* Save 'z' variable name */
parse_arg(&s);
nx = get_next_int(msg, &s);
ny = get_next_int(msg, &s);
if (nx==0 || ny==0) { parsed = 0; return; }
kx = get_next_int(msg, &s);
lx = get_next_int(msg, &s);
ky = get_next_int(msg, &s);
ly = get_next_int(msg, &s);
if (!parsed) return;
if (!(z = (float *) malloc(nx*ny*sizeof(float)))) out_of_mem();
get_2D_float_array(msg, &tmp_s, z, nx, ny); /* Use original name */
tmp_s = &return_string[0];
strcpy(tmp_s, s); /* Save 'clevel' variable name */
parse_arg(&s);
nlevel = get_next_int(msg, &s);
if (!nlevel) { parsed = 0; return; }
if (!(clevel = (float *) malloc(nlevel*sizeof(float)))) out_of_mem();
if (!parsed) { free((void *)z); return; }
get_float_array(msg, &tmp_s, clevel, nlevel);
#ifdef DEBUG
printf("plcont(%08x,%d,%d,%d,%d,%d,%d,%08x,%d,%08x);\n",
z,nx,ny,kx,lx,ky,ly,clevel,nlevel,&xform);
#endif
if (parsed)
plcont(z,nx,ny,kx,lx,ky,ly,clevel,nlevel,&xform);
free((void *) z);
}
void Rplend(msg, s)
struct RexxMsg *msg;
char *s;
{
still_going = 0; /* This function stops PlPlot */
#ifdef DEBUG
printf("plend();\n");
#endif
plend();
}
void Rplenv(msg, s)
struct RexxMsg *msg;
char *s;
{
float xmin, xmax, ymin, ymax;
int just, axis;
xmin = get_next_float(msg, &s);
xmax = get_next_float(msg, &s);
ymin = get_next_float(msg, &s);
ymax = get_next_float(msg, &s);
just = get_next_int(msg, &s);
axis = get_next_int(msg, &s);
#ifdef DEBUG
printf("plenv(%0.4f,%0.4f,%0.4f,%0.4f,%d,%d);\n",
xmin,xmax,ymin,ymax,just,axis);
#endif
if (parsed) plenv(xmin,xmax,ymin,ymax,just,axis);
}
void Rplerrx(msg, s)
struct RexxMsg *msg;
char *s;
{
int n;
float *xmin, *xmax, *y;
n = get_next_int(msg, &s);
if (n==0) parsed=0;
if (!parsed) return;
if (!(xmin = (float *) malloc(3*n*sizeof(float)))) out_of_mem();
xmax = &xmin[n];
y = &xmax[n];
get_float_array(msg, &s, xmin, n);
get_float_array(msg, &s, xmax, n);
get_float_array(msg, &s, y , n);
#ifdef DEBUG
printf("plerrx(%d,%08x,%08x,%08x);\n",
n,xmin,xmax,y);
#endif
if (parsed) plerrx(n,xmin,xmax,y);
free((void *) xmin);
}
void Rplerry(msg, s)
struct RexxMsg *msg;
char *s;
{
int n;
float *x, *ymin, *ymax;
n = get_next_int(msg, &s);
if (n==0) parsed=0;
if (!parsed) return;
if (!(x = (float *) malloc(3*n*sizeof(float)))) out_of_mem();
ymin = &x[n];
ymax = &ymin[n];
get_float_array(msg, &s, x , n);
get_float_array(msg, &s, ymin, n);
get_float_array(msg, &s, ymax, n);
#ifdef DEBUG
printf("plerry(%d,%08x,%08x,%08x);\n",
n,x,ymin,ymax);
#endif
if (parsed) plerry(n,x,ymin,ymax);
free((void *) x);
}
void Rplfont(msg, s)
struct RexxMsg *msg;
char *s;
{
int font;
font = get_next_int(msg, &s);
#ifdef DEBUG
printf("plfont(%d);\n", font);
#endif
if (parsed) plfont(font);
}
void Rplgra(msg, s)
struct RexxMsg *msg;
char *s;
{
#ifdef DEBUG
printf("plgra();\n");
#endif
plgra();
}
void Rplgrid3(msg, s)
struct RexxMsg *msg;
char *s;
{
float ztick;
ztick = get_next_float(msg, &s);
#ifdef DEBUG
printf("plgrid3(%0.4f);\n", ztick);
#endif
if (parsed) plgrid3(ztick);
}
void Rplgspa(msg, s)
struct RexxMsg *msg;
char *s;
{
float xmin, xmax, ymin, ymax;
plgspa(&xmin, &xmax, &ymin, &ymax);
write_next_float(msg, &s, xmin);
write_next_float(msg, &s, xmax);
write_next_float(msg, &s, ymin);
write_next_float(msg, &s, ymax);
#ifdef DEBUG
printf("plgspa(%0.4f,%0.4f,%0.4f,%0.4f);\n",
xmin,xmax,ymin,ymax);
#endif
}
void Rplhist(msg, s)
struct RexxMsg *msg;
char *s;
{
int n, nbin, oldwin;
float *data, datmin, datmax;
n = get_next_int(msg, &s);
if (n==0) parsed=0;
if (!parsed) return;
if (!(data = (float *) malloc(n*sizeof(float)))) out_of_mem();
get_float_array(msg, &s, data, n);
datmin = get_next_float(msg, &s);
datmax = get_next_float(msg, &s);
nbin = get_next_int(msg, &s);
oldwin = get_next_int(msg, &s);
#ifdef DEBUG
printf("plhist(%d,%08x,%0.4f,%0.4f,%d,%d);\n",
n,data,datmin,datmax,nbin,oldwin);
#endif
if (parsed) plhist(n,data,datmin,datmax,nbin,oldwin);
free((void *) data);
}
void Rpliff(msg, s)
struct RexxMsg *msg;
char *s;
{
int x1, y1, x2, y2 ;
char *name ;
x1 = get_next_int(msg, &s);
y1 = get_next_int(msg, &s);
x2 = get_next_int(msg, &s);
y2 = get_next_int(msg, &s);
name = get_char_pointer(msg, &s) ;
#ifdef DEBUG
printf("pliff(%d,%d,%d,%d,%s);\n",
x1, y1, x2, y2, name);
#endif
if (parsed) pliff(x1, y1, x2, y2, name);
}
void Rpljoin(msg, s)
struct RexxMsg *msg;
char *s;
{
float x1, y1, x2, y2;
x1 = get_next_float(msg, &s);
y1 = get_next_float(msg, &s);
x2 = get_next_float(msg, &s);
y2 = get_next_float(msg, &s);
#ifdef DEBUG
printf("pljoin(%0.4f,%0.4f,%0.4f,%0.4f);\n",
x1, y1, x2, y2);
#endif
if (parsed) pljoin(x1, y1, x2, y2);
}
void Rpllab(msg, s)
struct RexxMsg *msg;
char *s;
{
char *xlabel, *ylabel, *tlabel;
xlabel = get_char_pointer(msg, &s);
ylabel = get_char_pointer(msg, &s);
tlabel = get_char_pointer(msg, &s);
#ifdef DEBUG
printf("pllab('%s','%s','%s');\n",
xlabel, ylabel, tlabel);
#endif
if (parsed) pllab(xlabel, ylabel, tlabel);
}
void Rplline(msg, s)
struct RexxMsg *msg;
char *s;
{
int n;
float *x, *y;
n = get_next_int(msg, &s);
if (n==0) parsed=0;
if (!parsed) return;
if (!(x = (float *) malloc(2*n*sizeof(float)))) out_of_mem();
y = &x[n];
get_float_array(msg, &s, x, n);
get_float_array(msg, &s, y, n);
#ifdef DEBUG
printf("plline(%d,%08x,%08x);\n",
n, x, y);
#endif
if (parsed) plline(n, x, y);
free((void *) x);
}
void Rplmtex(msg, s)
struct RexxMsg *msg;
char *s;
{
char *side, *text;
float disp, pos, just;
side = get_char_pointer(msg, &s);
disp = get_next_float(msg, &s);
pos = get_next_float(msg, &s);
just = get_next_float(msg, &s);
text = get_char_pointer(msg, &s);
#ifdef DEBUG
printf("plmtex('%s',%0.4f,%0.4f,%0.4f,'%s');\n",
side, disp, pos, just, text);
#endif
if (parsed) plmtex(side, disp, pos, just, text);
}
void Rplot3d(msg, s)
struct RexxMsg *msg;
char *s;
{
float *x, *y, *z;
int *work, ly, nx, ny, opt;
char *tmp_s = &return_string[0];
strcpy(tmp_s, s); /* Save array variable names */
parse_arg(&s); parse_arg(&s); parse_arg(&s); /* Delete variable names */
parse_arg(&s); /* Get rid of 'WORK' argument */
ly = get_next_int(msg, &s);
nx = get_next_int(msg, &s);
ny = get_next_int(msg, &s);
opt = get_next_int(msg, &s);
if (nx==0 || ny==0) parsed=0;
if (!parsed) return;
if (!(x = (float *) malloc((nx+1)*(ny+1)*sizeof(float)))) out_of_mem();
y = &x[nx];
z = &y[ny];
if (!(work = (int *) malloc(4*MAX(nx,ny)*sizeof(int)))) out_of_mem();
get_float_array(msg, &tmp_s, x, nx);
get_float_array(msg, &tmp_s, y, ny);
get_2D_float_array(msg, &tmp_s, z, nx, ly);
#ifdef DEBUG
printf("plot3d(%08x,%08x,%08x,%08x,%d,%d,%d,%d);\n",
x,y,z,work,ly,nx,ny,opt);
#endif
if (parsed) plot3d(x,y,z,work,ly,nx,ny,opt);
free((void *) work);
free((void *) x);
}
void Rplpoin(msg, s)
struct RexxMsg *msg;
char *s;
{
int n, code;
float *x, *y;
n = get_next_int(msg, &s);
if (n==0) parsed=0;
if (!parsed) return;
if (!(x = (float *) malloc(2*n*sizeof(float)))) out_of_mem();
y = &x[n];
get_float_array(msg, &s, x, n);
get_float_array(msg, &s, y, n);
if (!parsed) { free((void *) x); return; }
code = get_next_int(msg, &s);
#ifdef DEBUG
printf("plpoin(%d,%08x,%08x,%d);\n",
n,x,y,code);
#endif
if (parsed) plpoin(n,x,y,code);
free((void *) x);
}
void Rplptex(msg, s)
struct RexxMsg *msg;
char *s;
{
float x, y, dx, dy, just;
char *text;
x = get_next_float(msg, &s);
y = get_next_float(msg, &s);
dx = get_next_float(msg, &s);
dy = get_next_float(msg, &s);
just = get_next_float(msg, &s);
text = get_char_pointer(msg, &s);
#ifdef DEBUG
printf("plptex(%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,'%s');\n",
x,y,dx,dy,just,text);
#endif
if (parsed) plptex(x,y,dx,dy,just,text);
}
void Rplschr(msg, s)
struct RexxMsg *msg;
char *s;
{
float def, scale;
def = get_next_float(msg, &s);
scale = get_next_float(msg, &s);
#ifdef DEBUG
printf("plschr(%0.4f,%0.4f);\n",def, scale);
#endif
if (parsed) plschr(def, scale);
}
void Rplside3(msg, s)
struct RexxMsg *msg;
char *s;
{
float *x, *y, *z;
int ly, nx, ny, opt;
char *tmp_s = &return_string[0];
strcpy(tmp_s, s); /* Save array variable names */
parse_arg(&s); parse_arg(&s); parse_arg(&s); /* Delete variable names */
ly = get_next_int(msg, &s);
nx = get_next_int(msg, &s);
ny = get_next_int(msg, &s);
opt = get_next_int(msg, &s);
if (nx==0 || ny==0) parsed=0;
if (!parsed) return;
if (!(x = (float *) malloc((nx+1)*(ny+1)*sizeof(float)))) out_of_mem();
y = &x[nx];
z = &y[ny];
get_float_array(msg, &tmp_s, x, nx);
get_float_array(msg, &tmp_s, y, ny);
get_2D_float_array(msg, &tmp_s, z, nx, ly);
#ifdef DEBUG
printf("plside3(%08x,%08x,%08x,%d,%d,%d,%d);\n",
x,y,z,ly,nx,ny,opt);
#endif
if (parsed) plside3(x,y,z,ly,nx,ny,opt);
free((void *) x);
}
void Rplsmaj(msg, s)
struct RexxMsg *msg;
char *s;
{
float def, scale;
def = get_next_float(msg, &s);
scale = get_next_float(msg, &s);
#ifdef DEBUG
printf("plsmaj(%0.4f,%0.4f);\n",def, scale);
#endif
if (parsed) plsmaj(def, scale);
}
void Rplsmin(msg, s)
struct RexxMsg *msg;
char *s;
{
float def, scale;
def = get_next_float(msg, &s);
scale = get_next_float(msg, &s);
#ifdef DEBUG
printf("plsmin(%0.4f,%0.4f);\n",def, scale);
#endif
if (parsed) plsmin(def, scale);
}
void Rplssym(msg, s)
struct RexxMsg *msg;
char *s;
{
float def, scale;
def = get_next_float(msg, &s);
scale = get_next_float(msg, &s);
#ifdef DEBUG
printf("plssym(%0.4f,%0.4f);\n",def, scale);
#endif
if (parsed) plssym(def, scale);
}
void Rplstar(msg, s)
struct RexxMsg *msg;
char *s;
{
int nx, ny;
nx = get_next_int(msg, &s);
ny = get_next_int(msg, &s);
#ifdef DEBUG
printf("plstar(%d,%d);\n",nx,ny);
#endif
if (parsed) plstar(nx, ny);
}
void Rplstyl(msg, s)
struct RexxMsg *msg;
char *s;
{
int nels, *mark=0, *space=0;
nels = get_next_int(msg, &s);
if (!parsed) return;
if (nels) {
if (!(mark = (int *) malloc(2*nels*sizeof(int)))) out_of_mem();
space = &mark[nels];
get_int_array(msg, &s, mark, nels);
get_int_array(msg, &s, space, nels);
#ifdef DEBUG
printf("plstyl(%d,%08x,%08x);\n",
nels, mark, space);
#endif
}
if (parsed) plstyl(nels, mark, space);
if (nels) {
free((void *) mark );
free((void *) space);
}
}
void Rplsvpa(msg, s)
struct RexxMsg *msg;
char *s;
{
float xmin, xmax, ymin, ymax;
xmin = get_next_float(msg, &s);
xmax = get_next_float(msg, &s);
ymin = get_next_float(msg, &s);
ymax = get_next_float(msg, &s);
#ifdef DEBUG
printf("plsvpa(%0.4f,%0.4f,%0.4f,%0.4f);\n",xmin,xmax,ymin,ymax);
#endif
if (parsed) plsvpa(xmin,xmax,ymin,ymax);
}
void Rplsym(msg, s)
struct RexxMsg *msg;
char *s;
{
int n, code;
float *x, *y;
n = get_next_int(msg, &s);
if (n==0) parsed=0;
if (!parsed) return;
if (!(x = (float *) malloc(2*n*sizeof(float)))) out_of_mem();
y = &x[n];
get_float_array(msg, &s, x, n);
get_float_array(msg, &s, y, n);
code = get_next_int(msg, &s);
#ifdef DEBUG
printf("plsym(%d,%08x,%08x,%d);\n",n,x,y,code);
#endif
if (parsed) plsym(n,x,y,code);
free((void *) x);
}
void Rpltext(msg, s)
struct RexxMsg *msg;
char *s;
{
#ifdef DEBUG
printf("pltext();\n");
#endif
pltext();
}
void Rplthicken(msg, s)
struct RexxMsg *msg;
char *s;
{
#ifdef DEBUG
printf("plthicken();\n");
#endif
plthicken();
}
void Rplvpor(msg, s)
struct RexxMsg *msg;
char *s;
{
float xmin, xmax, ymin, ymax;
xmin = get_next_float(msg, &s);
xmax = get_next_float(msg, &s);
ymin = get_next_float(msg, &s);
ymax = get_next_float(msg, &s);
#ifdef DEBUG
printf("plvpor(%0.4f,%0.4f,%0.4f,%0.4f);\n",xmin,xmax,ymin,ymax);
#endif
if (parsed) plvpor(xmin,xmax,ymin,ymax);
}
void Rplvsta(msg, s)
struct RexxMsg *msg;
char *s;
{
#ifdef DEBUG
printf("plvsta();\n");
#endif
plvsta();
}
void Rplw3d(msg, s)
struct RexxMsg *msg;
char *s;
{
float basex, basey, height, xmin, xmax, ymin, ymax, zmin, zmax, alt, az;
basex = get_next_float(msg, &s);
basey = get_next_float(msg, &s);
height = get_next_float(msg, &s);
xmin = get_next_float(msg, &s);
xmax = get_next_float(msg, &s);
ymin = get_next_float(msg, &s);
ymax = get_next_float(msg, &s);
zmin = get_next_float(msg, &s);
zmax = get_next_float(msg, &s);
alt = get_next_float(msg, &s);
az = get_next_float(msg, &s);
#ifdef DEBUG
printf("plw3d(%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f);\n",
basex,basey,height,xmin,xmax,ymin,ymax,zmin,zmax,alt,az);
#endif
if (parsed) plw3d(basex,basey,height,xmin,xmax,ymin,ymax,zmin,zmax,alt,az);
}
void Rplwind(msg, s)
struct RexxMsg *msg;
char *s;
{
float xmin, xmax, ymin, ymax;
xmin = get_next_float(msg, &s);
xmax = get_next_float(msg, &s);
ymin = get_next_float(msg, &s);
ymax = get_next_float(msg, &s);
#ifdef DEBUG
printf("plwind(%0.4f,%0.4f,%0.4f,%0.4f);\n",xmin,xmax,ymin,ymax);
#endif
if (parsed) plwind(xmin,xmax,ymin,ymax);
}
void set_transformation(msg, s)
struct RexxMsg *msg;
char *s;
{
#ifdef DEBUG
printf("Before: tr[6] = {%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f}\n",
tr[0], tr[1], tr[2], tr[3], tr[4], tr[5]);
#endif
tr[0] = get_next_float(msg, &s);
tr[1] = get_next_float(msg, &s);
tr[2] = get_next_float(msg, &s);
tr[3] = get_next_float(msg, &s);
tr[4] = get_next_float(msg, &s);
tr[5] = get_next_float(msg, &s);
#ifdef DEBUG
printf("After: tr[6] = {%0.4f,%0.4f,%0.4f,%0.4f,%0.4f,%0.4f}\n",
tr[0], tr[1], tr[2], tr[3], tr[4], tr[5]);
#endif
}
/*
* Here is our command association list. Note that in this case,
* we are setting the userdata field to be a function to call.
* Dispatch will still take place through disp(), so common head
* and tail stuff can go there.
*
* Commands are all lower case, so we match either upper or lower.
* (This is a requirement of minrexx.)
*/
struct rexxCommandList rcl[] = {
{ "pladv", (APTR)&Rpladv },
{ "plbeg", (APTR)&Rplbeg },
{ "plbin", (APTR)&Rplbin },
{ "plbox3", (APTR)&Rplbox3 },
{ "plbox", (APTR)&Rplbox },
{ "plclr", (APTR)&Rplclr },
{ "plcol", (APTR)&Rplcol },
{ "plcont", (APTR)&Rplcont },
{ "plend", (APTR)&Rplend },
{ "plenv", (APTR)&Rplenv },
{ "plerrx", (APTR)&Rplerrx },
{ "plerry", (APTR)&Rplerry },
{ "plfont", (APTR)&Rplfont },
{ "plgra", (APTR)&Rplgra },
{ "plgrid3", (APTR)&Rplgrid3 },
{ "plgspa", (APTR)&Rplgspa },
{ "pliff", (APTR)&Rpliff },
{ "plhist", (APTR)&Rplhist },
{ "pljoin", (APTR)&Rpljoin },
{ "pllab", (APTR)&Rpllab },
{ "plline", (APTR)&Rplline },
{ "plmtex", (APTR)&Rplmtex },
{ "plot3d", (APTR)&Rplot3d },
{ "plpoin", (APTR)&Rplpoin },
{ "plptex", (APTR)&Rplptex },
{ "plschr", (APTR)&Rplschr },
{ "plside3", (APTR)&Rplside3 },
{ "plsmaj", (APTR)&Rplsmaj },
{ "plsmin", (APTR)&Rplsmin },
{ "plssym", (APTR)&Rplssym },
{ "plstar", (APTR)&Rplstar },
{ "plstyl", (APTR)&Rplstyl },
{ "plsvpa", (APTR)&Rplsvpa },
{ "plsym", (APTR)&Rplsym },
{ "pltext", (APTR)&Rpltext },
{ "plthicken", (APTR)&Rplthicken },
{ "plvpor", (APTR)&Rplvpor },
{ "plvsta", (APTR)&Rplvsta },
{ "plw3d", (APTR)&Rplw3d },
{ "plwind", (APTR)&Rplwind },
{ "plset_tr", (APTR)&set_transformation },
{ NULL, NULL } } ;
/* Main rountine. Open up Libraries, print message,
* detach from CLI (eventually), and wait for ARexx messages
*/
main(argc, argv)
int argc;
char *argv[];
{
long rexxbit ;
/* Maybe we should do more safety initialization here !?!? */
#ifdef LATTICE
onexit(dnRexxPort) ;
#endif
printf("This is RexxPlPlot V0.3 by Glenn M. Lewis built on PlPlot 1.1a\n") ;
printf(" by Tony Richardson with modifcations by Sam Paolucci.\n") ;
printf(" IFF, Preferences and minrexx support by Tomas Rokicki.\n") ;
rexxbit = upRexxPort("PlPlot", rcl, "plot", &disp) ;
if (argc > 1)
asyncRexxCmd(argv[1]) ;
else
printf("[waiting for ARexx to send me a command...]\n");
still_going = 1;
while (still_going) { /* Main loop */
Wait(rexxbit);
dispRexxPort() ;
}
/*
* With Rexx, we need to bring the port down. You might make this
* part of exit() for programs that have multiple paths to exit.
*/
dnRexxPort() ;
Exit(0); /* Call the AmigaDOS routine to shut down */
}
/* Make sure that the string is copied before it is chopped up. ARexx
* doesn't like other programs tampering with its strings
*/
static char work_string[256];
/*
* This is our main dispatch function.
* If everything else was successful, we return a 0 to ARexx.
* Otherwise, we return a failure of 20 to indicate that the arguments
* were messed up.
*/
void disp(msg, dat, s)
register struct RexxMsg *msg;
register struct rexxCommandList *dat;
char *s;
{
parsed = 1; /* Assume that everything went OK */
strcpy(work_string, s);
((void (*)()) dat->userdata)(msg, work_string);
if (!parsed)
replyRexxCmd(msg, 20L, 10L, NULL); /* Fail */
else if (return_result)
replyRexxCmd(msg, 0L, 0L, return_string); /* It worked */
else
replyRexxCmd(msg, 0L, 0L, NULL); /* It worked */
}
void
out_of_mem()
{
printf("Ooops. Out of memory. Sorry. I died.\n");
still_going = 0;
plend();
Exit(0);
}
/* We have to make our own exit so that when PlPlot exit()'s, we close ARexx */
#ifndef LATTICE
void
_exit()
{
dnRexxPort();
Exit(0); /* Call the AmigaDOS exit function */
}
#endif
void
uppercase(s)
register char *s;
{
while (*s) {
if (islower(*s)) *s = toupper(*s);
s++;
}
}
/* Here are all of the parsing routines to perform the conversion magic */
char *parse_arg(s)
char **s;
{
register char *p, *p2;
char delimiter;
quoted = 0; /* Let routines know if it was a string */
p = *s;
while (*p && (isspace(*p) || *p=='(' || *p==',')) p++; /* Pass junk */
p2 = p;
if (*p2 == '\"' || *p2 == '\'') { /* This arg is enclosed in quotes */
quoted = 1;
delimiter = *p2++;
p++; /* Chop off first delimiter */
while (*p2 && *p2 != delimiter) p2++; /* Find matching delimiter */
if (*p2) *p2++ = '\0'; /* Chop off final delimiter */
while (*p2 && (isspace(*p2) || *p2==')' || *p2==',')) p2++;
*s = p2; /* Point to next argument */
return(p);
}
/* Argument was not enclosed in quotes. Find any delimiter */
while (*p2 && !isspace(*p2) && *p2 != ',' && *p2 != ')') p2++;
if (*p2) *p2++ = '\0'; /* Chop off final delimiter */
*s = p2;
return(p);
}
void check_for_stems(msg, s) /* Replace variable stems with integer */
struct RexxMsg *msg;
char *s;
{
char temp[256], *value;
register int i, j;
uppercase(s);
for (i=0; s[i]; )
if (s[i++] == '.') {
for (j=0; s[i+j] && s[i+j]!='.'; j++) ;
if (j) strncpy(temp, &s[i], j);
temp[j] = '\0';
GetRexxVar(msg, temp, &value);
if (!(*value)) { parsed = 0; return; }
/* Got the variable contents - make room in the string */
strcpy(temp, &s[i+j]);
/* Check that 'value' is an integer */
for (j=0; value[j]; j++)
if (value[j] <= '0' || value[j] >= '9') { parsed=0; return; }
strcpy(&s[i], value);
strcpy(&s[i+j], temp); /* Add contents onto end */
i += j;
}
}
int get_next_int(msg, s)
struct RexxMsg *msg;
char **s;
{
register char *p;
char *value;
p = parse_arg(s); /* Return pointer to argument, advance 's' past it */
if ((*p >= '0' && *p <= '9') || *p == '-' || *p == '+')
return(atoi(p)); /* It's a number */
check_for_stems(msg, p);
if (!parsed) return(0);
GetRexxVar(msg, p, &value);
if (!(*value)) { parsed = 0; return(0); }
return(atoi(value));
}
float get_next_float(msg, s)
struct RexxMsg *msg;
char **s;
{
register char *p;
char *value;
p = parse_arg(s); /* Return pointer to argument, advance 's' past it */
if ((*p >= '0' && *p <= '9') || *p == '-' || *p == '+')
return((float)atof(p)); /* It's a number */
check_for_stems(msg, p);
if (!parsed) return(0.0);
GetRexxVar(msg, p, &value);
if (!(*value)) { parsed = 0; return(0.0); }
return((float)atof(value));
}
static char save_it_away[256];
char *get_char_pointer(msg, s)
struct RexxMsg *msg;
char **s;
{
register char *p;
char *value;
p = parse_arg(s); /* Return pointer to argument, advance 's' past it */
if (quoted) return(p); /* It's a quoted string... return it */
strcpy(save_it_away, p); /* Save it away for later */
check_for_stems(msg, save_it_away);
if (!parsed) { parsed=1; return(p); } /* Not a stem - return as string */
GetRexxVar(msg, save_it_away, &value);
if (!(*value)) { return(p); } /* Not a variable... return it */
/* Yes, it was a variable. Pass the pointer of its value: */
return(value);
}
void get_float_array(msg, s, array, n)
struct RexxMsg *msg;
char **s;
float *array;
int n;
{
register int i;
register char *p;
char *value;
p = parse_arg(s); /* Return pointer to argument, advance 's' past it */
uppercase(p);
/* If there is only one value, then there is no need for a stem */
if (n==1) {
GetRexxVar(msg, p, &value);
if (*value) {
array[0] = (float) atof(value);
return;
}
/* If it got to this line, couldn't find the variable. Check stem. */
}
/* Start reading all of its values */
for (i=0; i<n; i++) {
sprintf(save_it_away, "%s.%d", p, i+1); /* Generate the stem */
GetRexxVar(msg, save_it_away, &value);
if (!(*value)) { parsed = 0; return; }
array[i] = (float) atof(value);
}
return;
}
void get_2D_float_array(msg, s, array, nx, ny)
struct RexxMsg *msg;
char **s;
float *array;
int nx, ny;
{
register int i, j;
register char *p;
char *value;
p = parse_arg(s); /* Return pointer to argument, advance 's' past it */
uppercase(p);
/* Start reading all of its values */
for (i=0; i<nx; i++) {
for (j=0; j<ny; j++) {
sprintf(save_it_away, "%s.%d.%d", p, i+1, j+1); /* Generate the stem */
GetRexxVar(msg, save_it_away, &value);
if (!(*value)) { parsed = 0; return; }
array[i*ny+j] = (float) atof(value);
}
}
return;
}
void get_int_array(msg, s, array, n)
struct RexxMsg *msg;
char **s;
int *array, n;
{
register int i;
register char *p;
char *value;
p = parse_arg(s); /* Return pointer to argument, advance 's' past it */
uppercase(p);
/* If there is only one value, then there is no need for a stem */
if (n==1) {
GetRexxVar(msg, p, &value);
if (*value) {
array[0] = atoi(value);
return;
}
/* If it got to this line, couldn't find the variable. Check stem. */
}
/* Start reading all of its values */
for (i=0; i<n; i++) {
sprintf(save_it_away, "%s.%d", p, i+1); /* Generate the stem */
GetRexxVar(msg, save_it_away, &value);
if (!(*value)) { parsed = 0; return; }
array[i] = atoi(value);
}
return;
}
void write_next_float(msg, s, val)
struct RexxMsg *msg;
char **s;
float val;
{
register char *p;
p = parse_arg(s); /* Return pointer to argument, advance 's' past it */
check_for_stems(msg, s);
if (!parsed) return;
/* Attempt to write the value */
sprintf(save_it_away, "%0.8f", val);
if (SetRexxVar(msg, p, save_it_away, strlen(save_it_away)))
parsed = 0; /* Wasn't able to write */
return;
}